<?php

namespace App\Http\Controllers\Home;

use Illuminate\Support\Facades\DB;
use App\Http\Requests;
use App\Http\Controllers\Home\HomeBaseController;
use Illuminate\Support\Facades\Input;

class HomeController extends HomeBaseController {

	public function __construct() {
		parent::__construct();
	}

	public function index() {
		return view('admin.index.test');
		$data = 112;
		$users = DB::table('apps')->get();

//		$result = DB::table('apps')->insert([
//				['app_id'=>'Laravel1','app_secret'=>'laravel@test.com','app_name'=>'123'],
//				['app_id'=>'Academy2','app_secret'=>'academy@test.com','app_name'=>'123'],
//				['app_id'=>'LaravelAcademy3','app_secret'=>'laravel-academy@test.com','app_name'=>'123']
//		]);
		echo "<pre>";dd($users);exit;
		return $data;
	}

	public function testdata() {
		$app_id = Input::get("app_id", 0);
		$app_secret = Input::get("app_secret");
		$app_name = Input::get("app_name");
		$app_desc = Input::get("app_desc");
		$data = [
			"app_id" => $app_id,
			"app_secret" => $app_secret,
			"app_name" => $app_name,
			"app_desc" => $app_desc,
			"created_at" => time(),
		];
		$int_last_id = DB::table("apps")->insertGetId($data);
		echo "<pre>";echo '<a href="/home/edit?id='.$int_last_id.'">编辑</a>';
		echo "<pre>";echo '<a href="/home/del?id='.$int_last_id.'">删除</a>';exit;
		return response()->json(['return_code'=>'3','return_message'=>'fuck!you','data'=>Input::get(),'get'=>$_POST]);
	}

	public function edit() {
		$int_id = Input::get("id");
		$ary_data = DB::table('apps')->where('id',$int_id)->first();
		return view("home.index.edit", ['ary_page_data' => $ary_data]);
	}

	public function update() {
		$int_id = Input::get("id");
		$app_id = Input::get("app_id", 0);
		$app_secret = Input::get("app_secret");
		$app_name = Input::get("app_name");
		$app_desc = Input::get("app_desc");
		$data = [
			"app_id" => $app_id,
			"app_secret" => $app_secret,
			"app_name" => $app_name,
			"app_desc" => $app_desc,
			"updated_at" => time(),
		];
		$affected = DB::table('apps')->where('id',$int_id)->update($data);
		return redirect("home/index");
	}

	public function del() {
		$int_id = Input::get("id");
		$deleted = DB::table('apps')->where('id', $int_id)->delete();
		return redirect("home/index");
		echo "<pre>";dd($deleted);
	}


	public function test() {
		return view('home.index.demo');
		$data = 112;
		$users = DB::table('apps')->get();

//		$result = DB::table('apps')->insert([
//				['app_id'=>'Laravel1','app_secret'=>'laravel@test.com','app_name'=>'123'],
//				['app_id'=>'Academy2','app_secret'=>'academy@test.com','app_name'=>'123'],
//				['app_id'=>'LaravelAcademy3','app_secret'=>'laravel-academy@test.com','app_name'=>'123']
//		]);
		echo "<pre>";dd($users);exit;
		return $data;
	}
}